Project Part 2 Group 14

#install.packages("jpeg")
library(jpeg)

Question 1

The starting point of the task is to read the image, and separate the image for both the rows and columns respectively to analyze and alter the data easily.

if (!requireNamespace("BiocManager", quietly = TRUE))
  install.packages("BiocManager")

BiocManager::install("EBImage")
## Bioconductor version 3.9 (BiocManager 1.30.10), R 3.6.1 (2019-07-05)
## Installing package(s) 'EBImage'
## package 'EBImage' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\mehme\AppData\Local\Temp\RtmpisAmfs\downloaded_packages
## Installation path not writeable, unable to update packages: boot, foreign,
##   KernSmooth, Matrix, mgcv, nlme, survival
## Old packages: 'igraph'
library(EBImage)

image <- readJPEG("group_14_gri.jpg")

image_row <- image
image_column <- image

The means and variances of the rows and columns respectively are given by the code. In the apply function, 1 represents the rows and 2 represents columns.

row_means <- apply(image,1,mean)
row_variance <- apply(image,1,var)

column_means <- apply(image,2,mean)
column_variance <- apply(image,2,var)

#install.packages("qcc")
require(qcc)
## Loading required package: qcc
## Package 'qcc' version 2.7
## Type 'citation("qcc")' for citing this R package in publications.
i <- 0
j <-0

QUESTION 1 - PART A

The matrix is divided into 80x5 subgroups. With the qcc package, it’s possible to detect out of control points, or outliers, and change the data points. We could have detected the outliers in another way, however, with qcc package, we can both create the charts and tinker with the data. After creating the matrices, qcc gives us an opportunity to use UCL and LCL control limits, by checking the values in the rowmeans matrix we eliminate the out of control points by assigning them to the value of 0. Thus, image_row is updated.

for(i in 1:400 ){
  
  rowmatrix <- matrix(image[i,],nrow = 80,ncol = 5)
  
  xbar <- qcc(rowmatrix, type = "xbar")
  
  rowmeans <- apply(rowmatrix,1,mean)
  
  for(j in 1:80){
    if( rowmeans[j] < xbar$limits[1] || rowmeans[j] > xbar$limits[2] ){
      image_row[i,((j-1)*5+1):(((j-1)*5)+5)] <- rep(0,5)
    }
    
  }
}

The code below shows the difference between the original image and the image with row outliers assigned to the value of 0. In the image with row outliers sweeped, black dots appeared on some of the locations on the image. The black dots represent the outliers that are given the value of 0.

op1 <- par()
plot(c(0, 820), c(0, 401), xlab = "", ylab = "")
title(paste("The Image With Row Outliers Sweeped And The Original Image"))
rasterImage(image_row, 0, 0, 400, 400, interpolate = FALSE)
rasterImage(image, 430, 0, 830, 400,interpolate = FALSE )

par(op1)
## Warning in par(op1): grafiksel parametre "cin" belirlenemez
## Warning in par(op1): grafiksel parametre "cra" belirlenemez
## Warning in par(op1): grafiksel parametre "csi" belirlenemez
## Warning in par(op1): grafiksel parametre "cxy" belirlenemez
## Warning in par(op1): grafiksel parametre "din" belirlenemez
## Warning in par(op1): grafiksel parametre "page" belirlenemez